<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../jquery/jquery-3.2.1.min.js"></script>
</head>
<style>

</style>

<body>
    <h1>注册页面</h1>
    <form action="">
        <div>
            <p>用户名</p>
            <input type="text" name="user_name" id="user_name">
        </div>
        <div>
            <p>密码</p>
            <input type="password" name="user_password" id="user_password">
        </div>
        <p></p>
        <button>
            提交
        </button>
    </form>
</body>
<script>
    $('button').on('click', (e) => {
        console.log("发送请求")
        e.preventDefault();

        $.ajax({
            method: 'post',
            url: 'http://localhost:8080/register',
            data: {
                name: $('input[type="text"]').val(),
                password: $('input[type="password"]').val()
            },
            success: (data) => {
                console.log(data);
                window.alert("注册成功，请进入登录页面")
            },
            error: (err) => {
                console.log(err);
            }
        })
    })
</script>

</html>